﻿using System;
using Enyim.Caching;
using Ayatta.Contract;
using System.Web.Mvc;
using Ayatta.Contract.Domain;
using Web.Base.Extensions;
using Web.Manage.Controllers;
using Web.Manage.Areas.Order.Models;

namespace Web.Manage.Areas.Order.Controllers
{
    public class HomeController : AdminBaseController
    {
        public HomeController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        /// <summary>
        /// 订单列表
        /// </summary>
        /// <param name="page">当前页</param>
        /// <param name="size">分页大小</param>
        /// <param name="orderId">订单Id</param>
        /// <param name="userId">用户id</param>
        /// <param name="isSeller">是否为卖家</param>
        /// <param name="category">订单类别</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="commentStatus">评价状态</param>
        /// <param name="beginDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <returns></returns>
        public ActionResult Index(int page = 1, int size = 20, string orderId = null, int? userId = null,
                                        bool isSeller = false,
                                       OrderCategory category = OrderCategory.Normal,
                                       OrderStatus? orderStatus = null, byte? commentStatus = null,
                                       DateTime? beginDate = null, DateTime? endDate = null)
        {
            var model = new HomeControllerModel.Index();
            model.OrderId = orderId;
            model.Orders = OrderService.GetPagedOrders(page, size, orderId, userId, null, isSeller, null, category, orderStatus, commentStatus, beginDate, endDate).ToPagedList(page, size);

            return PartialView(model);
        }

        /// <summary>
        /// 订单详细信息
        /// </summary>
        /// <param name="param">订单Id</param>
        /// <returns></returns>
        public ActionResult Detail(string param)
        {
            var model = new HomeControllerModel.Detail();
            var order= OrderService.GetOrder(param, null, true, true);
            model.Order = order;
            if (order.Status == OrderStatus.SellerSendPart || order.Status == OrderStatus.WaitBuyerConfirm || order.Status == OrderStatus.Finished)
            {
                model.Shippings = OrderService.GetOrderShippings(param);
            }
            return PartialView(model);
        }
    }
}
